package action;

import java.util.List;

import entity.Contest;
import service.ContestDAO;
import service.impl.ContestDAOImpl;

public class ContestAction extends SuperAction {

	List<Contest> conList;

	/**
	 * 如果不在 param 中设置
	 * pageSize 默认为 10，每页10条数据
	 * currentPage 默认为 1，当前页为第一页
	 */
	int pageSize = 10;

	int currentPage = 1;

	String typeName;

	String keyword;

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public List<Contest> getConList() {
		return conList;
	}

	public void setConList(List<Contest> conList) {
		this.conList = conList;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public String getTypeName() {
		return typeName;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	// 查询所有竞赛默认按照时间
	public String queryAllDefault() {
		ContestDAO cDao = new ContestDAOImpl();
		conList = cDao.queryAllDefault(currentPage, pageSize);
		return SUCCESS;
	}

	// 查询所有按照热度
	public String queryAllSortByHot() {
		ContestDAO cDao = new ContestDAOImpl();
		conList = cDao.queryAllSortByHot(currentPage, pageSize);
		return SUCCESS;
	}

	// 查询所有竞赛按照类别
	public String queryAllSortByType() {
		ContestDAO cDao = new ContestDAOImpl();
		conList = cDao.queryAllSortByType(currentPage, pageSize);
		return SUCCESS;
	}
	
	// 用关键字对比赛名称模糊匹配
	public String queryAllByKeyword() {
		ContestDAO cDao = new ContestDAOImpl();
		conList = cDao.queryAllByKeyword(currentPage, pageSize, keyword);
		return SUCCESS;
	}

	// 通过类别来筛选比赛
	public String filterAllByType() {
		ContestDAO cDao = new ContestDAOImpl();
		conList = cDao.filterAllByType(currentPage, pageSize, typeName);
		return SUCCESS;
	}
	
	// 默认执行时间排序
	public String execute() {
		queryAllDefault();
		return SUCCESS;
	}
}
